package com.hyphenate.easeui.adapter;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.adapter.CustomAdapter;
import com.joplus.housekeeper.bean.RecommandCardBean;
import com.joplus.housekeeper.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by zisheng on 2017/8/23.
 */

public class RecommandCardAdapter2 extends CustomAdapter {
    Context context;
    List<RecommandCardBean.DataBean.RecommendListBean> list;
    private final LayoutInflater layout;

    public RecommandCardAdapter2(Context context, List<RecommandCardBean.DataBean.RecommendListBean> recommendList) {
        this.context = context;
        this.list = recommendList;
        layout = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int c) {
        return c;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i) {
        View view = layout.inflate(R.layout.item_recommand_card_horizontal, null);
        final RecommandCardBean.DataBean.RecommendListBean recommendListBean = list.get(i);
        ImageView iv_img = (ImageView) view.findViewById(R.id.iv_img);
        TextView tv_name = (TextView) view.findViewById(R.id.tv_name);
        TextView tv_introduction = (TextView) view.findViewById(R.id.tv_introduction);
        ImageView tv_type_name = (ImageView) view.findViewById(R.id.tv_type_name);
        StringUtils.setText(tv_name, recommendListBean.getRecommendName());

        tv_introduction.setText(getColon(recommendListBean.getRecommendName()));
//        StringUtils.setText(holder.tv_type_name,bean.getRecommendName());

        //推荐标签(1、24小时最热2、最新上线3、猜您喜欢4、会员福利5、无)
        if (!StringUtils.isEmpty(recommendListBean.getRecommendLabel())) {
            switch (recommendListBean.getRecommendLabel()) {
                case "1":
                    tv_type_name.setImageResource(R.drawable.rcard_hot);
                    break;
                case "2":
                    tv_type_name.setImageResource(R.drawable.rcard_new);
                    break;
                case "3":
                    tv_type_name.setImageResource(R.drawable.rcard_guess_like);
                    break;
                case "4":
                    tv_type_name.setImageResource(R.drawable.rcard_member_onley);
                    break;
                case "5":
                    tv_type_name.setImageResource(0);
                    break;
            }

        }
        iv_img.setTag(recommendListBean.getImg() + i);
        ImageLoader.getInstance().displayImage(recommendListBean.getImg(), iv_img);
        //设置加粗
        tv_name.getPaint().setFakeBoldText(true);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return view;
    }

    public SpannableStringBuilder getColon(String s) {

        SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
//        stringBuilder.append("“");
        AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(16, true);
        //stringBuilder.setSpan(absoluteSizeSpan, 0, 1, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        //stringBuilder.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, 1, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        if (!StringUtils.isEmpty(s)) {
            stringBuilder.append(s);
        }

        return stringBuilder;

    }
}
